package hr.fer.apr.ht41337.lab2.funkcije;

import hr.fer.apr.ht41337.lab2.Tocka;

public class F2 implements FunkcijaOgranicena {

	@Override
	public double getXd(int i) {
		if (i < 0 || i > 1)
			throw new IllegalArgumentException("pogresan index: i=" + i);
		return -100;
	}

	@Override
	public double getXg(int i) {
		if (i < 0 || i > 1)
			throw new IllegalArgumentException("pogresan index: i=" + i);
		return 100;
	}

	@Override
	public boolean zadovoljavaEksplicitnaOgranicenja(Tocka t){
		if (t.dimenzija != 2)
			throw new IllegalArgumentException("tocka pogresnih dimenzija");
		for (int i = 0; i < getDimenzija(); i++)
			if (t.getX(i) < getXd(i) || t.getX(i) > getXg(i))
				return false;
		return true;
	}

	@Override
	public boolean zadovoljavaImplicitnaOgranicenja(Tocka t) {
		if ((t.getX(0) - t.getX(1) <= 0) && (t.getX(0) - 2 <= 0))
			return true;
		return false;
	}

	@Override
	public int getDimenzija() {
		return 2;
	}

	@Override
	public double getValue(Tocka t) { 
		double value = Math.pow(t.getX(0) - 4, 2) + 4*Math.pow(t.getX(1) - 2, 2);
		return value;
	}

}
